<template>
    <el-container v-if="true" class="layout-container-demo" style="height: 100%">
        <el-aside>
            <div class="pagetitle">
                <span>订单管理</span>
            </div>
            <el-menu 
                :default-openeds="['2']" 
                :default-active = defaultMenu
                text-color="#C4C4C4"
                mode="vertical"
            >
                <el-menu-item index="1" @click="BackToOrder()">
                    <span style="font-size:15px">订单区</span>
                </el-menu-item>
                <div v-if="false" class="">
                    <div class="unready">
                        <div class="textpart">成型车间</div>
                    </div>
                    <div class="unready">
                        <div class="textpart">烧结</div>
                    </div>
                    <div class="ready">
                        <div class="textpart">整形车间</div>
                    </div>
                    <div class="ready">
                        <div class="textpart">机加工</div>
                    </div>
                    <div class="unready">
                        <div class="textpart">热处理</div>
                    </div>
                    <div class="unready">
                        <div class="textpart">外协</div>
                    </div>
                    <div class="ready">
                        <div class="textpart">包装</div>
                    </div> 
                </div>
            </el-menu>
            <div v-if="orderid !== 0" class="donebtn">
                <el-button style="width:80%; height:100px;" :type="BtnType">
                    <span style="font-size:20px">完成并归档</span> 
                </el-button>
            </div>
            <div v-if="orderid === 0" class="donebtn">
                <el-button style="width:80%; height:100px;" type='warning' @click="dialogvisible = true">
                    <span style="font-size:20px">增加订单</span> 
                </el-button>
            </div>
        </el-aside> 
        <el-container>
            <el-header style="text-align: right; font-size: 12px">
                <el-dropdown trigger="click">
                    <span style="line-height:30px;margin-top:15px;margin-right:20px;color:white;font-size:20px">
                        {{username}}
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item @click="clearuser()" style="height:30px;width:28px;font-size:15px">登出</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </el-header>
            <el-main>
                <order-page v-if=" orderid === 0 "></order-page>
                <order-info-page v-if=" orderid !== 0 "></order-info-page>
            </el-main>
        </el-container>
    </el-container>
    <el-dialog v-model="dialogvisible" title="请输入订单信息" style="height:550px">
        <el-scrollbar max-height="400px">
            <el-form style="max-width: 500px" label-width="100px">
                <el-form-item label="订单编号: ">
                    <el-input v-model="form.ddID" required/>
                </el-form-item>
                <el-form-item label="客户编号: ">
                    <el-input v-model="form.cliID" required/>
                </el-form-item>
                <el-form-item label="图号: ">
                    <el-input v-model="form.BPID" />
                </el-form-item>
                <el-form-item label="客户图号: ">
                    <el-input v-model="form.cliBPID" />
                </el-form-item>
                <el-form-item label="产品规格: ">
                    <el-input v-model="form.ProSize" />
                </el-form-item>
                <el-form-item label="订单数量: ">
                    <el-input v-model="form.ProNum" required/>
                </el-form-item>
                <el-form-item label="材质: ">
                    <el-input v-model="form.CZ" />
                </el-form-item>
                <el-form-item label="下单时间: ">
                    <el-date-picker value-format="x" v-model="form.XdTime" required type="datetime" placeholder="下单时间" style="width: 100%"/>
                </el-form-item>
                <el-form-item label="交期: ">
                    <el-date-picker value-format="x" v-model="form.JqTime" required type="datetime" placeholder="交期" style="width: 100%"/>
                </el-form-item>
                <el-form-item label="产品单重: ">
                    <el-input v-model="form.ProW" />
                </el-form-item>
                <el-form-item label="订单粉量: ">
                    <el-input v-model="form.ddFL" />
                </el-form-item>
                <el-form-item label="等级: ">
                    <el-select v-model="form.DJ" placeholder="请选择等级" required style="width:100%">
                        <el-option label="1" value=1 />
                        <el-option label="2" value=2 />
                        <el-option label="3" value=3 />
                        <el-option label="4" value=4 />
                    </el-select>
                </el-form-item>
            </el-form>
        </el-scrollbar>
        <div style="text-align:right;margin-top:10px">
            <el-button type="primary" size="large" @click="Submite">
                提交
            </el-button>
        </div>
        
    </el-dialog>
</template>

<script lang="ts">
import {
    ElContainer,
    ElAside,
    ElHeader,
    ElFooter,
    ElMenu,
    ElMenuItem,
    ElMenuItemGroup,
    ElSubMenu,
    ElIcon,
    ElDropdown,
    ElDropdownItem,
    ElDropdownMenu,
    ElMain,
    ElButton,
    ElForm,
    ElFormItem,
    ElDialog,
    ElInput,
    ElDatePicker,
    ElOption,
    ElSelect,
    ElScrollbar,
    ElMessage,
} from "element-plus";
import OrderInfoPage from './workshop/orderinfo.vue'
import OrderPage from './workshop/order.vue'
import { useRouter } from 'vue-router'
import { toRefs, reactive, onMounted } from 'vue'
import bus from '../utils'
import UserStore from '../store/userstore' 
import axios from 'axios'

export default {
    components: {
        ElContainer,
        ElAside,
        ElHeader,
        ElFooter,
        ElMenu,
        ElMenuItem,
        ElMenuItemGroup,
        ElSubMenu,
        ElIcon,
        ElDropdown,
        ElDropdownItem,
        ElDropdownMenu,
        ElMain,
        ElButton,
        ElForm,
        ElFormItem,
        ElDialog,
        ElInput,
        ElSelect,
        ElDatePicker,
        ElOption,
        ElScrollbar,
        OrderInfoPage,
        OrderPage,
    },
    setup(){
        const store = UserStore()
        const router = useRouter()
        const data = reactive({
            username:'' as any,
            orderid:0,
            defaultMenu: '1',
            BtnType:'danger',
            Btndis:'disabled',
            orderData1: [] as any,
            orderData2: [] as any,
            dialogvisible: false,
            form:{
                ddID:0,
                cliID:'' as any,
                BPID:'' as any,
                cliBPID:'' as any,
                ProSize:'' as any,
                ProNum:0,
                CZ:'' as any,
                XdTime:'' as any,
                JqTime:'' as any,
                ProW:0.0,
                ddFL:0,
            },
        })
        // const form = reactive({
            
        // })
        const methods = reactive({
            BackToOrder:() => {
                data.orderid = 0
                data.defaultMenu = '1'
                store.orderid = -1
            },
            clearuser: () => {
                store.username = ''
                router.replace({
                    name:"login"    
                })
            },
            Submite: () => {
                axios.get(('http://localhost:9000/insertdd'),{params:data.form})
                data.dialogvisible = false
                bus.emit(`refreshorder`)
                ElMessage.success('增加订单成功！')
            }
        })
        bus.on(`EnterOrder`,(msg : any) => {
            data.orderid = 1
            data.defaultMenu = '0'
        })
        onMounted(() => {
            data.username = store.username
        })
        return{
            ...toRefs(data),
            ...toRefs(methods),
        }
    },
};
</script>

<style>
    @import url(../assets/css/index.css);
</style>

